import {queryUserList, deleteUser, updateUser} from "../services/memberApi";

export default {
    namespace: 'memberList',
    state: {
        status: undefined,
    },

    effects: {
        * queryUserList({payload}, {call, put}) {
            yield put({
                type: 'changeSubmitting',
                payload: true,
            });
            const response = yield call(queryUserList, payload);
            yield put({
                type: 'queryUserHandle',
                payload: response,
            });
            yield put({
                type: 'changeSubmitting',
                payload: false,
            });
        },
        * deleteUser({payload, callback}, {call, put}) {
            yield put({
                type: 'changeSubmitting',
                payload: true,
            });
            const response = yield call(deleteUser, payload);
            yield put({
                type: 'changeSubmitting',
                payload: false,
            });
            if (callback) callback(response);
        },
        * updateUser({payload, callback}, {call, put}) {
            yield put({
                type: 'changeSubmitting',
                payload: true,
            });
            const response = yield call(updateUser, payload);
            yield put({
                type: 'changeSubmitting',
                payload: false,
            });
            if (callback) callback(response);
        },
    },
    reducers: {
        changeSubmitting(state, {payload}) {
            return ({
                ...state,
                submitting: payload,
            })
        },
        queryUserHandle(state, {payload}) {
            return ({
                ...state,
                userInfo: payload["resultData"]["userInfo"]["list"],
                pagination: payload["resultData"]["userInfo"]["pagination"],
                rankNames: payload["resultData"]["rankNames"],
            })
        },
    }
};




